package com.jereh.topnews.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.jereh.topnews.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class SimpleActivity extends AppCompatActivity {
    private ListView list;
    private SimpleAdapter adapter;
    //map的键名称
    private String[] from={"title","img1","img2","img3","summary"};
    private int[] to={R.id.title,R.id.img1,R.id.img2,R.id.img3,R.id.summary};
    //标题数据
    private String[] titles={"范冰冰是个大美女","王宝强何时打完官司","今天是个好日子"};
    //图片一的数据
    private int [] img1s={R.mipmap.dog1,R.mipmap.dog2,R.mipmap.dog3};
    //图片二的数据
    private int [] img2s={R.mipmap.dog4,R.mipmap.dog5,R.mipmap.dog6};
    //图片三的数据
    private int [] img3s={R.mipmap.dog7,R.mipmap.dog8,R.mipmap.dog9};
    //简介数据
    private String[] summaries={"简介1","简介2","简介3"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);
        list=(ListView)findViewById(R.id.simple);
        adapter=new SimpleAdapter(this,getData(),R.layout.adapter_simple_demo,from,to);
        list.setAdapter(adapter);
    }
    private List<HashMap<String,Object>> getData() {
        List<HashMap<String,Object>> list=new ArrayList<>();
        for(int i=0;i<titles.length;i++) {
            HashMap<String,Object> map=new HashMap<>();
            map.put(from[0],titles[i]);
            map.put(from[1],img1s[i]);
            map.put(from[2],img2s[i]);
            map.put(from[3],img3s[i]);
            map.put(from[4],summaries[i]);
            list.add(map);
        }
        return list;
    }
}
